py-cvs-rel2_1 (Rev 1.2) merge
[python/dscho.git] / Mac / IDE scripts / Widget demos / WidgetTest.py
blobf88b0599630151089b1166b47b8007e974474cfb
1 import W
3 # define some callbacks
4 def callback():
5 window.close()
7 def checkcallback(value):
8 print "hit the checkbox", value
10 def radiocallback(value):
11 print "hit radiobutton #3", value
13 def scrollcallback(value):
14 widget = window.hbar
15 if value == "+":
16 widget.set(widget.get() - 1)
17 elif value == "-":
18 widget.set(widget.get() + 1)
19 elif value == "++":
20 widget.set(widget.get() - 10)
21 elif value == "--":
22 widget.set(widget.get() + 10)
23 else: # in thumb
24 widget.set(value)
25 print "scroll...", widget.get()
27 def textcallback():
28 window.et3.set(window.et1.get())
30 def cancel():
31 import EasyDialogs
32 EasyDialogs.Message("Cancel!")
34 # make a non-sizable window
35 #window = W.Window((200, 300), "Fixed Size")
37 # make a sizable window
38 window = W.Window((200, 300), "Variable Size!", minsize = (200, 300))
40 # make some edit text widgets
41 window.et1 = W.EditText((10, 10, 110, 110), "Hallo!", textcallback)
42 window.et2 = W.EditText((130, 40, 60, 30), "one!")
43 window.et3 = W.EditText((130, 80, -10, 40), "two?")
45 # a button
46 window.button = W.Button((-70, 10, 60, 16), "Close", callback)
48 # a checkbox
49 window.ch = W.CheckBox((10, 130, 160, 16), "Check (command \xa4)", checkcallback)
51 # set of radio buttons (should become easier/nicer)
52 thebuttons = []
53 window.r1 = W.RadioButton((10, 150, 180, 16), "Radio 1 (cmd 1)", thebuttons)
54 window.r2 = W.RadioButton((10, 170, 180, 16), "Radio 2 (cmd 2)", thebuttons)
55 window.r3 = W.RadioButton((10, 190, 180, 16), "Radio 3 (cmd 3)", thebuttons, radiocallback)
56 window.r1.set(1)
58 # a normal button
59 window.cancelbutton = W.Button((10, 220, 60, 16), "Cancel", cancel)
61 # a scrollbar
62 window.hbar = W.Scrollbar((-1, -15, -14, 16), scrollcallback, max = 100)
64 # some static text
65 window.static = W.TextBox((10, 260, 110, 16), "Schtatic")
67 # bind some keystrokes to functions
68 window.bind('cmd\xa4', window.ch.push)
69 window.bind('cmd1', window.r1.push)
70 window.bind('cmd2', window.r2.push)
71 window.bind('cmd3', window.r3.push)
72 window.bind('cmdw', window.button.push)
73 window.bind('cmd.', window.cancelbutton.push)
75 window.setdefaultbutton(window.button)
76 # open the window
77 window.open()
79 if 0:
80 import time
81 for i in range(20):
82 window.et2.set(`i`)
83 #window.et2.SetPort()
84 #window.et2.draw()
85 time.sleep(0.1)